import 'package:pacsun/utils/notifyMsg.dart';
import 'package:pacsun/utils/share_utils.dart';
import 'package:pacsun/view/login/loginPage.dart';
import 'package:pacsun/view/task/task_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../provider/themeProv.dart' show ThemeModeProvider;
import 'package:pacsun/provider/sysTagsProvider.dart' show SysTagsProvider;
import '../../provider/userProv.dart' show UserProvider;

class HomeMain extends StatefulWidget {
  const HomeMain({super.key});

  @override
  State<HomeMain> createState() => _HomeMainState();
}

class _HomeMainState extends State<HomeMain> {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      /// system init putting here///////
      _loadSystemTags();

      /// system init putting here///////
    });
  }

  Future<void> _loadSystemTags() async {
    try {
      await Provider.of<SysTagsProvider>(context, listen: false)
          .loadSystemTags();
    } catch (e) {
      debugPrint('Error loading tags: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
        // ElevatedButton(
        //   onPressed: () {
        //     context.read<ThemeModeProvider>().toggleTheme();
        //   },
        //   child: Text('Changing mode'),
        // ),
        // ElevatedButton(
        //   onPressed: () {
        //     context.read<UserProvider>().toggleUserType();
        //   },
        //   child: Text('Changing user type'),
        // ),
        // ElevatedButton(
        //   onPressed: () {
        //     Navigator.push(context,
        //         MaterialPageRoute(builder: (context) => const TaskPage()));
        //   },
        //   child: Text('Task page'),
        // ),
        ElevatedButton(
          onPressed: () {
            Navigator.push(
                context, MaterialPageRoute(builder: (context) => LoginPage()));
          },
          child: Text('Login Page'),
        ),
        // ElevatedButton(
        //   onPressed: () {},
        //   child: Text('Share Toktik'),
        // ),
        // ElevatedButton(
        //   onPressed: () async{
        //     final picker = ImagePicker();
        //     final pickedFile = await picker.pickImage(source: ImageSource.gallery);
        //     ShareUtils.shareImageToYoutube(pickedFile!.path);
        //   },
        //   child: Text('Share ins'),
        // ),

        ElevatedButton(
          onPressed: () {
            try {
              final userProvider =
                  Provider.of<UserProvider>(context, listen: false);

              //For development (uncomment when needed)
              userProvider.mockLoginForDev(0);
              notifyMsg('Mock login as common user successfully.', context);
            } catch (e) {
              notifyMsg('Mock login as common user failed ${e}', context);
            }
          },
          child: Text('Mock Login as Common User'),
        ),
        ElevatedButton(
          onPressed: () {
            try {
              final userProvider =
                  Provider.of<UserProvider>(context, listen: false);

              //For development (uncomment when needed)
              userProvider.mockLoginForDev(1);
              notifyMsg('Mock login as common user successfully.', context);
            } catch (e) {
              notifyMsg('Mock login as common user failed ${e}', context);
            }
          },
          child: Text('Mock Login as Creator User'),
        ),
      ]),
    );
  }
}
